package com.ll.app.controller;

import com.ll.base.dto.ApiResultDTO;
import com.ll.domain.tenant.biz.TenantDomainService;
import com.ll.domain.tenant.dto.TenantDTO;
import com.ll.domain.user.biz.UserDomainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 企业内部内部-小程序Quick-Start示例代码 实现了最简单的免密登录（免登）功能
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "首页API")
public class IndexController {

    private final UserDomainService userDomainService;
    private final TenantDomainService tenantDomainService;

    @ResponseBody
    @ApiOperation(value = "获取权限")
    @RequestMapping(value = "/getPower", method = RequestMethod.POST)
    public ApiResultDTO getPower(@RequestParam(value = "tenantId") Long tenantId) {
        TenantDTO tenantDTO = tenantDomainService.getById(tenantId, true);
        return ApiResultDTO.success(tenantDTO.getPowers());
    }

    @ResponseBody
    @ApiOperation(value = "首页DIY的数据")
    @RequestMapping(value = "/indexDiy", method = RequestMethod.POST)
    public ApiResultDTO indexDiy(@RequestParam(value = "tenantId") Long tenantId) {
        TenantDTO tenantDTO = tenantDomainService.getById(tenantId, true);
        return ApiResultDTO.success(tenantDTO.getIndexDiy());
    }

    @ResponseBody
    @ApiOperation(value = "钉钉登陆接口")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ApiResultDTO login(@RequestParam(value = "authCode") String requestAuthCode) {
        return ApiResultDTO.success(userDomainService.dingLogin(requestAuthCode));
    }

    @ResponseBody
    @ApiOperation(value = "初始化钉钉部门人员接口（勿调用）")
    @RequestMapping(value = "/init", method = RequestMethod.POST)
    public ApiResultDTO init(@RequestParam(value = "deptId") Long deptId) {
        return ApiResultDTO.success(userDomainService.init(deptId));
    }


}


